home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / spread25 / chkbk.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  4KB  |  143 lines

  1. unit chkbk;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, Grids, spread;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Spread1: TSpread;
  12.     BitBtn1: TBitBtn;
  13.     OpenDialog1: TOpenDialog;
  14.     SaveDialog1: TSaveDialog;
  15.     procedure BitBtn1Click(Sender: TObject);
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure Spread1ButtonClick(col, row: Longint; Name, Caption: String);
  18.   private
  19.     { Private declarations }
  20.     procedure SetupSheet;
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TForm1.BitBtn1Click(Sender: TObject);
  33. begin
  34.      If Opendialog1.execute then
  35.      begin
  36.        If not Spread1.loadfromfile(Opendialog1.filename) then
  37.          MessageDlg('Error loading file',mterror,[mbok],0)
  38.        else
  39.          Spread1.recalculate;
  40.      end;
  41. end;
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.      setupsheet;
  46. end;
  47.  
  48. procedure TForm1.SetupSheet;
  49. var
  50.    c,r : longint;
  51.    Br : TBrush;
  52.    formula : string;
  53. begin
  54.      spread1.colwidths[2] := 120;
  55.      With Spread1 do
  56.      begin
  57.        for c := 0 to colcount - 1 do
  58.        begin
  59.          SetCellAlignment(c,0,taCenter);
  60.          SetCelltype(c,0,cttext);
  61.          case c of
  62.            0 : SetFormula(c,0,'Date');
  63.            1 : SetFormula(c,0,'Ref#');
  64.            2 : SetFormula(c,0,'Payee');
  65.            3 : SetFormula(c,0,'Deposit');
  66.            4 : SetFormula(c,0,'Check');
  67.            5 : SetFormula(c,0,'Balance');
  68.          end;
  69.        end;
  70.        for c := 0 to 4 do
  71.        begin
  72.          case c of
  73.            0 :
  74.            begin
  75.             SetCelltype(c,1,cttext);
  76.             SetFormula(c,1,'Beg Bal');
  77.             LockCell(c,1);
  78.            end;
  79.            5 : SetCelltype(c,1,ctformula);
  80.            else
  81.            begin
  82.             SetCelltype(c,1,ctformula);
  83.             LockCell(c,1);
  84.            end;
  85.          end;
  86.        end;
  87.        for r := 2 to rowcount - 1 do
  88.        begin
  89.          SetCelltype(0,r,ctdate);
  90.          SetCelltype(1,r,cttext);
  91.          SetCelltype(2,r,cttext);
  92.          SetCelltype(3,r,ctformula);
  93.          SetCellAlignment(3,r,TaRightjustify);
  94.          SetCelltype(4,r,ctformula);
  95.          SetCellAlignment(4,r,TaRightjustify);
  96.          SetCelltype(5,r,ctformula);
  97.          SetCellAlignment(5,r,TaRightjustify);
  98.          Lockcell(5,r);
  99.        end;
  100.        Br := TBrush.Create;
  101.        Br.color := clyellow;
  102.        r := 2;
  103.        while r < rowcount do
  104.        begin
  105.          SetRowBrush(r,Br);
  106.          r := r + 2;
  107.        end;
  108.        Br.Free;
  109. (*       for r := 2 to rowcount - 1 do
  110.          Lockcell(5,r);  *)
  111.        SetCellAlignment(5,1,taRightJustify);
  112.        for r := 2 to rowcount - 1 do
  113.        begin
  114.          SetCelltype(5,r,ctformula);
  115.          formula := '=f'+inttostr(r-1)+'+d'+inttostr(r)+'-e'+inttostr(r);
  116.          SetFormula(5,r,formula);
  117.        end;
  118.  
  119.        MakeButton(colcount-1,rowcount-1,'Save...');
  120.        recalculate;
  121.      end;
  122.  
  123. end;
  124. procedure TForm1.Spread1ButtonClick(col, row: Longint; Name,
  125.   Caption: String);
  126. begin
  127.      If Caption = 'Clear' then
  128.      begin
  129.         Spread1.MakeNewSheet;
  130.         setupsheet;
  131.      end
  132.      else if Caption = 'Save...' then
  133.      begin
  134.        If savedialog1.execute then
  135.        begin
  136.          if not Spread1.savetofile(savedialog1.filename) then
  137.            Messagedlg('Error saving file',mterror,[mbok],0);
  138.        end;
  139.      end;
  140. end;
  141.  
  142. end.
  143.